home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 1 / Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso / FILES / DEV / I-Z / OnScreen MDEF.sit / MDEF / MDEF.main.c next >
Text File  |  1993-03-22  |  3KB  |  102 lines

  1. /******************** MDEF.main.c *********************/
  2.  
  3. #include <SetUpA4.h>
  4.  
  5. #define kMenuIconWidth    24
  6. #define kItemHeight     20
  7. #define kScrollHeight   7
  8. #define kSystemMDEFID    0
  9.  
  10.  
  11. /************************* PROC PTR for an MDEF ***************************/
  12. typedef pascal void (*MDEFProcPtr) (short message, MenuHandle theMenu, RectPtr menuRect, 
  13.                            Point hitPoint,short *whichItem);  
  14.  
  15. /***************************declarations***********************************/
  16. pascal void main (short message, MenuHandle theMenu, RectPtr menuRect, 
  17.                   Point hitPoint,short *whichItem);
  18.                   
  19. /****************************definitions***********************************/
  20.  
  21. void    JumpToSystemMDEF(short message, MenuHandle theMenu, RectPtr menuRect, 
  22.                            Point hitPoint,short *whichItem) {
  23.         Handle MDEFHandle;    
  24.  
  25.     MDEFHandle = GetResource ('MDEF', kSystemMDEFID);
  26.     if (MDEFHandle == nil)
  27.             return;
  28.     else
  29.     {
  30.         char    saveState;
  31.         
  32.         saveState = HGetState(MDEFHandle);
  33.         HLock (MDEFHandle);
  34.         /* The next line actually jumps to the code segment */
  35.         (* (MDEFProcPtr) (*MDEFHandle)) (message,theMenu,menuRect,hitPoint,whichItem);
  36.         HSetState(MDEFHandle,saveState);
  37.     }
  38. }
  39. /*****************************************************************************/
  40. /*                          Main                                             */
  41. /*****************************************************************************/
  42. /* This routine just gets the hitpoint from the Menu Manager then adjusts it */
  43. /* so that the MDEF either gets shown entirely on the screen or the largest  */
  44. /* portion gets shown on the screen. This makes the MDEF 100% compatible.    */
  45. /*****************************************************************************/
  46. pascal void main (short message, MenuHandle theMenu, RectPtr menuRect, 
  47.                   Point hitPoint,short *whichItem) {
  48.         
  49.     GrafPtr        Screen;
  50.     short         itemCount, mouseItem;
  51.     Boolean        MenuScrolls = FALSE;
  52.     
  53.     RememberA0();
  54.     SetUpA4();
  55.  
  56.     HLock(theMenu);
  57.     
  58.     itemCount = CountMItems( theMenu );
  59.  
  60.     switch (message) {
  61.  
  62.         default:
  63.             JumpToSystemMDEF(message,theMenu,menuRect,hitPoint,whichItem);
  64.             break;
  65.     
  66.  
  67.         /* Calc the Rect Size */
  68.         case mPopUpMsg: { 
  69.             GrafPtr     theScreen;     
  70.             RectPtr     screenRect;
  71.             short     height   = kItemHeight*itemCount;
  72.             
  73.             GetWMgrPort( &theScreen );
  74.             
  75.             /* Get the screen Rect */
  76.             screenRect = &(*theScreen).portRect;
  77.                
  78.             /* Adjust the top of the menu */
  79.             
  80.             if (hitPoint.h + height > screenRect->bottom ) {
  81.                 hitPoint.h = (screenRect->bottom) - height;
  82.                 if (hitPoint.h + height > screenRect->bottom - 24 && itemCount == 2) {
  83.                     hitPoint.h = hitPoint.h - (height/2);
  84.                     }/*if*/
  85.                 }/*if*/
  86.             
  87.             /* Make sure that the menu does not pop up above the screen.*/
  88.             if (hitPoint.h < screenRect->top) hitPoint.h = screenRect->top + 5;
  89.             
  90.             /* Call the System MDEF */
  91.             JumpToSystemMDEF(message,theMenu,menuRect,hitPoint,whichItem); 
  92.             
  93.             break; }/* mPopUpMsg */
  94.             
  95.         }/*switch*/
  96.     
  97.     HUnlock(theMenu);
  98. CleanUp:
  99.     /*Restore A4*/
  100.     RestoreA4();
  101.         
  102. }/*main*/